#!/usr/bin/env python
# -*- coding: utf8 -*-

import init,threading,time

def thread(ssh,hostname):
    stdin,stdout,stderr = ssh.exec_command('python /cihi/scripts/check_hw.py',timeout=3)
    global result
    result[hostname] = eval(stdout.read())

k = init.INIT()
threads = []
result = {}
for i in k.getClient('all'):
    s,t,e = k.getSession(i)
    if e:
        print e
        continue
    hostname = i['hostname']
    threads.append(threading.Thread(target=thread,args=(s,hostname)))
for t in threads:
    t.start()
for t in threads:
    t.join()
print result
    
